Repository navigation
Migrate CMake.Sdk, Templating, XliffTasks and FileCatalog tasks to multithreaded MSBuild - #17507
Conversation
…ltithreaded MSBuild Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: be19d794-fe4f-43fe-9e6e-f6e6b13ec6e7
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
It changes execution/threading and path-resolution behavior across multiple build task assemblies, which merits a final human review plus full build/test validation.
Review tier: Lite
Findings: 1
New issues introduced by this change (1)
| Severity | Finding |
|---|---|
src/Microsoft.DotNet.XliffTasks/Model/XlfDocument.cs — CreateSchemaSet() allocates resource streams and XmlReaders without disposing them. Even though… |
What changed in this PR
This PR migrates additional self-contained Arcade task assemblies (CMake.Sdk, Templating, XliffTasks, FileCatalog) to be safe for in-proc multi-threaded MSBuild execution by opting into [MSBuildMultiThreadableTask], implementing IMultiThreadableTask, and resolving paths through TaskEnvironment (with canonicalization restored where outputs/comparisons require it).
Changes:
- Opt tasks into multi-threaded execution and inject
TaskEnvironmentfor project-relative path/environment resolution. - Flow
AbsolutePathinto task-private helpers/models and reintroduce canonicalization viaGetCanonicalForm()where paths are compared/emitted/embedded. - Make XLIFF schema validation state thread-safe via
Lazy<XmlSchemaSet>and pre-compilation.
| File | Description |
|---|---|
| src/Microsoft.DotNet.XliffTasks/Tasks/XlfTask.cs | Base task now implements IMultiThreadableTask and uses AbsolutePath for document loading. |
| src/Microsoft.DotNet.XliffTasks/Tasks/UpdateXlf.cs | Uses TaskEnvironment.GetAbsolutePath for file IO and corrects FileNotFoundException.FileName comparison. |
| src/Microsoft.DotNet.XliffTasks/Tasks/TranslateSource.cs | Resolves inputs/outputs via TaskEnvironment and canonicalizes embedded rewritten paths. |
| src/Microsoft.DotNet.XliffTasks/Tasks/TransformTemplates.cs | Resolves copy/load/save paths through TaskEnvironment for thread-safe execution. |
| src/Microsoft.DotNet.XliffTasks/Tasks/SortXlf.cs | Resolves XLF path IO through TaskEnvironment. |
| src/Microsoft.DotNet.XliffTasks/Tasks/GatherTranslatedSource.cs | Canonicalizes emitted DependentUpon metadata using TaskEnvironment + canonical form. |
| src/Microsoft.DotNet.XliffTasks/Tasks/EnsureAllResourcesTranslated.cs | Resolves XLF load paths through TaskEnvironment. |
| src/Microsoft.DotNet.XliffTasks/Model/XlfDocument.cs | Makes schema set initialization thread-safe and compiled before use. |
| src/Microsoft.DotNet.XliffTasks/Model/Document.cs | Switches Load/Save APIs to AbsolutePath to ensure task-boundary path resolution. |
| src/Microsoft.DotNet.XliffTasks/Microsoft.DotNet.XliffTasks.csproj | Links in AbsolutePathExtensions polyfill for canonicalization. |
| src/Microsoft.DotNet.CMake.Sdk/src/GetCMakeArtifactsFromFileApi.cs | Task becomes multi-threadable; resolves/canonicalizes paths for comparisons and item specs. |
| src/Microsoft.DotNet.CMake.Sdk/src/CreateCMakeFileApiQuery.cs | Task becomes multi-threadable; resolves filesystem paths via TaskEnvironment. |
| src/Microsoft.DotNet.CMake.Sdk/Microsoft.DotNet.CMake.Sdk.csproj | Links in AbsolutePathExtensions polyfill. |
| src/Microsoft.DotNet.Build.Tasks.Templating/src/Microsoft.DotNet.Build.Tasks.Templating.csproj | Links in AbsolutePathExtensions polyfill. |
| src/Microsoft.DotNet.Build.Tasks.Templating/src/GenerateFileFromTemplate.cs | Task becomes multi-threadable; resolves/canonicalizes output and template paths. |
| src/Microsoft.DotNet.Build.Tasks.FileCatalog/GenerateFileCatalog.cs | Task becomes multi-threadable; resolves file/catalog output paths via TaskEnvironment. |
| src/Microsoft.DotNet.Build.Tasks.FileCatalog/CatalogEntry.cs | Accepts AbsolutePath so file IO uses task-resolved paths. |
| src/Microsoft.DotNet.Build.Tasks.FileCatalog/CatalogBuilder.cs | Accepts AbsolutePath for AddFile/WriteTo to propagate resolved paths. |
| src/Microsoft.DotNet.Build.Tasks.FileCatalog.Tests/CatalogTests.cs | Updates tests to provide AbsolutePath inputs via TaskEnvironment.Fallback. |
| src/Common/Internal/AbsolutePathExtensions.cs | Adds internal GetCanonicalForm() polyfill via Path.GetFullPath for fully-qualified inputs. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
FileInfo/DirectoryInfo are BCL types the analyzer already treats as safe via .FullName, so the model layer keeps no Microsoft.Build.Framework dependency and FileInfo.FullName supplies the canonicalization that GetAbsolutePath omits. This removes the need for the internal GetCanonicalForm polyfill. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: be19d794-fe4f-43fe-9e6e-f6e6b13ec6e7
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
There are remaining correctness issues to address (notably disposal of schema resource streams in XlfDocument and updating impacted documentation crefs after the FileInfo API shift).
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review tier: Lite
Findings: 1
New issues introduced by this change (1)
| Severity | Finding |
|---|---|
src/Microsoft.DotNet.XliffTasks/Model/Document.cs — This PR changes Document.Save from Save(string) to Save(FileInfo), but at least one XML doc… |
Pre-existing issues (1)
| Severity | Finding |
|---|---|
src/Microsoft.DotNet.XliffTasks/Model/XlfDocument.cs — CreateSchemaSet() allocates resource streams and XmlReaders without disposing them. Even though… View comment |
Suppressed comments (1)
src/Microsoft.DotNet.XliffTasks/Model/XlfDocument.cs:318
- CreateSchemaSet creates manifest resource streams and XmlReaders without disposing them. Since this is now called once and cached for the lifetime of the process via Lazy, it can permanently leak handles/memory. Use
usingfor the streams/readers (and consider throwing a clear error if the embedded resource stream is null).
System.IO.Stream xmlSchemaResourceStream = typeof(XlfDocument).Assembly.GetManifestResourceStream("XliffTasks.Model.xml.xsd");
XmlReader xmlSchemaReader = XmlReader.Create(xmlSchemaResourceStream);
System.IO.Stream xliffSchemaResourceStream = typeof(XlfDocument).Assembly.GetManifestResourceStream("XliffTasks.Model.xliff-core-1.2-transitional.xsd");
XmlReader xliffSchemaReader = XmlReader.Create(xliffSchemaResourceStream);
Task classes carry AbsolutePath and convert at the call boundary into Document, CatalogBuilder and CatalogEntry, which stay on FileInfo so they keep no Microsoft.Build.Framework dependency. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: be19d794-fe4f-43fe-9e6e-f6e6b13ec6e7
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
There are at least two correctness/robustness issues (a potentially-missed FileNotFoundException catch filter due to path canonicalization and undisposed schema resources) that should be addressed before approval.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review tier: Lite
Findings: 2
New issues introduced by this change (1)
| Severity | Finding |
|---|---|
src/Microsoft.DotNet.XliffTasks/Tasks/UpdateXlf.cs — The catch filter compares FileNotFoundException.FileName to absoluteXlfPath.Value, but XlfDocument… |
Pre-existing issues (2)
| Severity | Finding |
|---|---|
src/Microsoft.DotNet.XliffTasks/Model/XlfDocument.cs — CreateSchemaSet() allocates resource streams and XmlReaders without disposing them. Even though… View comment |
|
src/Microsoft.DotNet.XliffTasks/Model/Document.cs — This PR changes Document.Save from Save(string) to Save(FileInfo), but at least one XML doc… View comment |
Suppressed comments (1)
src/Microsoft.DotNet.XliffTasks/Model/XlfDocument.cs:318
- CreateSchemaSet creates resource streams and XmlReaders without disposing them. Even though this runs once per process, leaving these IDisposable resources undisposed can leak handles/memory in long-lived MSBuild nodes (especially with node reuse).
System.IO.Stream xmlSchemaResourceStream = typeof(XlfDocument).Assembly.GetManifestResourceStream("XliffTasks.Model.xml.xsd");
XmlReader xmlSchemaReader = XmlReader.Create(xmlSchemaResourceStream);
System.IO.Stream xliffSchemaResourceStream = typeof(XlfDocument).Assembly.GetManifestResourceStream("XliffTasks.Model.xliff-core-1.2-transitional.xsd");
XmlReader xliffSchemaReader = XmlReader.Create(xliffSchemaResourceStream);
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: be19d794-fe4f-43fe-9e6e-f6e6b13ec6e7
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
A couple of the updated model-layer APIs introduce avoidable runtime issues (missing argument validation and undisposed schema readers/streams) that should be corrected before merging.
Review tier: Lite
Findings: 2
Pre-existing issues (3)
| Severity | Finding |
|---|---|
src/Microsoft.DotNet.XliffTasks/Tasks/UpdateXlf.cs — The catch filter compares FileNotFoundException.FileName to absoluteXlfPath.Value, but XlfDocument… View comment |
|
src/Microsoft.DotNet.XliffTasks/Model/XlfDocument.cs — CreateSchemaSet() allocates resource streams and XmlReaders without disposing them. Even though… View comment |
|
src/Microsoft.DotNet.XliffTasks/Model/Document.cs — This PR changes Document.Save from Save(string) to Save(FileInfo), but at least one XML doc… View comment |
Suppressed comments (3)
Previously missed (1) — in code that hasn't changed since the last review.
src/Microsoft.DotNet.XliffTasks/Model/Document.cs:32
- Document.Load(FileInfo) no longer validates its argument. Passing null now causes a NullReferenceException when accessing path.FullName, whereas the prior string-based implementation would throw an ArgumentNullException from the BCL call.
This issue also appears on line 59 of the same file.
src/Microsoft.DotNet.XliffTasks/Model/XlfDocument.cs:318
- CreateSchemaSet creates manifest-resource streams and XmlReaders but never disposes them. Since the schema set is compiled immediately, these can be safely disposed to avoid leaking handles/resources.
System.IO.Stream xmlSchemaResourceStream = typeof(XlfDocument).Assembly.GetManifestResourceStream("XliffTasks.Model.xml.xsd");
XmlReader xmlSchemaReader = XmlReader.Create(xmlSchemaResourceStream);
System.IO.Stream xliffSchemaResourceStream = typeof(XlfDocument).Assembly.GetManifestResourceStream("XliffTasks.Model.xliff-core-1.2-transitional.xsd");
XmlReader xliffSchemaReader = XmlReader.Create(xliffSchemaResourceStream);
src/Microsoft.DotNet.XliffTasks/Model/Document.cs:71
- Document.Save(FileInfo) also lacks null-argument validation, which can produce a NullReferenceException (path or path.Directory) instead of a clear argument error. Adding an explicit guard keeps failures deterministic and easier to diagnose.
public void Save(FileInfo path)
{
//On Windows:
// Readers will prevent the file from being overwritten due to FileShare.Read.
// Readers can read in parallel, but when there's contention with a writer, the retrying will kick in to resolve it.
//On Unix:
// FileShare.Read does nothing, but...
// File.Replace is implemented with rename system call that will mean that even though writers can overwrite while
// reading is happening, each reader will see file before or after overwrite, not in between
EnsureContent();
string tempPath = Path.Combine(path.Directory.FullName, Path.GetRandomFileName());
…FoundException filter, fix stale cref Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: be19d794-fe4f-43fe-9e6e-f6e6b13ec6e7
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
There is at least one concrete correctness issue in updated documentation comments (malformed XML doc tag) that should be fixed before approval.
Review tier: Lite
Findings: 1
Pre-existing issues (1)
| Severity | Finding |
|---|---|
src/Microsoft.DotNet.XliffTasks/Model/Document.cs — This PR changes Document.Save from Save(string) to Save(FileInfo), but at least one XML doc… View comment |
Issues resolved since last review (2)
| Severity | Finding |
|---|---|
src/Microsoft.DotNet.XliffTasks/Tasks/UpdateXlf.cs — The catch filter compares FileNotFoundException.FileName to absoluteXlfPath.Value, but XlfDocument… View resolved comment |
|
src/Microsoft.DotNet.XliffTasks/Model/XlfDocument.cs — CreateSchemaSet() allocates resource streams and XmlReaders without disposing them. Even though… View resolved comment |
Suppressed comments (1)
Previously missed (1) — in code that hasn't changed since the last review.
src/Microsoft.DotNet.XliffTasks/Model/TranslatableNode.cs:38
- The XML documentation comment is not well-formed: the
tag opened on line 34 is never closed (line 37 re-opens
instead). This can break documentation generation and produce compiler warnings (e.g., CS1570) if/when XML docs are enabled.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: be19d794-fe4f-43fe-9e6e-f6e6b13ec6e7
There was a problem hiding this comment.
Copilot review overview
🔵 Needs a closer look
It changes core build-task execution semantics (in-proc multithreading and path canonicalization) across multiple task areas, which warrants final human validation despite no specific issues found in review.
Review tier: Lite
Findings: None
Issues resolved since last review (1)
| Severity | Finding |
|---|---|
src/Microsoft.DotNet.XliffTasks/Model/Document.cs — This PR changes Document.Save from Save(string) to Save(FileInfo), but at least one XML doc… View resolved comment |


Next safe subset of #17381: the CMake.Sdk, Templating, XliffTasks and FileCatalog tasks.
[MSBuildMultiThreadableTask]/IMultiThreadableTaskand resolve every path throughTaskEnvironment.GetAbsolutePathbefore touching the filesystem.XlfDocument's racy staticXmlSchemaSetbecomes aLazy<T>that compiles the set before publishing it, sinceXmlSchemaSetmutates itself during validation.Document,CatalogBuilderandCatalogEntrytakeFileInforather thanstring. The analyzer's transitive check needs a typed path to flow into the file I/O, andFileInfokeeps these model types free of anyMicrosoft.Build.Frameworkdependency - same approach asNuGetVersionUpdaterin Opt a second set of tasks into multithreaded execution #17497. Task classes stay onAbsolutePathand convert at the call boundary.UpdateXlfcomparesFileNotFoundException.FileNameagainst the absolute path it passed in, not the original relative one.GetAbsolutePathdeliberately omits butPath.GetFullPathperformed, wherever the result is compared, emitted as an output property or item metadata, or embedded in a generated file:GetCMakeArtifactsFromFileApi(directory match and artifact item specs),GenerateFileFromTemplate(ResolvedOutputPath),GatherTranslatedSource(DependentUpon) andTranslateSource(paths rewritten into the translated document).GetCanonicalForm()polyfill because that API is not public in the MSBuild packages this repo consumes; tracked for removal by Remove the AbsolutePath.GetCanonicalForm polyfill once Arcade consumes an MSBuild with the public API #17506.One pre-existing quirk is deliberately left alone:
GetCMakeArtifactsFromFileApionly normalizesdirSourcewhen it is not already rooted, so a rooted value is still compared un-normalized. That predates this change and has no CWD dependency.